package string;
/**
 * String支持正则表达式的方法三：
 * String replaceAll(String regex, String replacement)
 * 将当前字符串中满足正则表达式的部分替换为给定内容
 */
public class ReplaceAllDemo {
    public static void main(String[] args) {
        String line = "abc123def456ghi";
        //将当前字符串中的数字部分替换为“#NUMBER#
        String newLine = line.replaceAll("[0-9]+", "#NUMBER#");
        System.out.println(newLine); //abc#NUMBER#def#NUMBER#ghi
        String newLine2 = line.replaceAll("[a-z]+", "#WORD#");
        System.out.println(newLine2); //#WORD#123#WORD#456#WORD#




        //和谐用语的表现
        String regex = "(wqnmlgb|cnm|dsb|nc|wrsndm|fw|djb)";
        String message = "wqnmlgb!你个dsb！你怎么这么nc，会不会玩！你个djb";
        message = message.replaceAll(regex,"***");
        System.out.println(message); //***!你个***！你怎么这么***，会不会玩！你个***

    }
}






















